<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Video extends CF_Controller
{

	public function __construct()
	{
		parent::__construct();
		$this->load->library('form_validation');
		$this->load->model('Shicai_mdl');
	}

	public function index()
	{
		$kw = htmlentities($this->input->get('kw'));
		!$kw && $kw = '美食';
		$per_page = max(1, intval($this->input->get('per_page')));
		$limit = 21; //每页显示数

		$data['caipu_class'] = '菜谱视频大全';

		$video_array = $this->_curl($kw, $per_page, $limit);

		$data['video_array'] = $video_array['data']['list'];
		/* 分页配置 */
		$this->load->library('pagination');
		$config['base_url'] = site_url('video/index/?kw='.$kw);
		$config['total_rows'] = $video_array['data']['count'];
		$config['per_page'] = $limit; 
		$config['use_page_numbers'] = TRUE;
		$config['page_query_string'] = TRUE;
		$this->pagination->initialize($config); 
		$this->load->view('video',$data);
	}

	public function play()
	{
		$vid = htmlentities($this->input->get('vid'));
		$data['vid'] = $vid;
		$this->load->view('video_play',$data);
	}

	public function _curl($kw = '', $page = 1, $pageSize = 10)
	{		
		$url = "http://search.ku6.com/api/compatibleSearch.htm?q=$kw&format=json&s={$pageSize}&p={$page}";
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_HEADER, 0); 
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
		$geo = curl_exec($ch);
		curl_close($ch);	
		
		$geo = json_decode($geo, TRUE);	

		return $geo;
	}
}

/* End of file meishi.php */
/* Location: ./application/controllers/resource/meishi.php */